package org.dzms.dao;

import java.util.List;

import org.dzms.commons.DataHandler;
import org.dzms.commons.PageHandler;
import org.dzms.entity.Userinfos;

public class PersonDao {
	
	//查询所有的信息
	public List<Userinfos> findAll(){
		String sql = "select * from userinfos";
		return DataHandler.query(sql, null, Userinfos.class);
	}
	
	//保存用户信息-基本信息？
	public void saveBasicuser(Userinfos us){
		String sql = "insert into userinfos(username,usersex,alwaddress,actaddress,introducemyself) values(?,?,?,?,?)";
		DataHandler.update(sql, new Object[]{us.getUsername(),us.getUsersex(),us.getAlwaddress(),us.getActaddress(),us.getIntroducemyself()});
	}
	
	
	//更新基本信息用户（有修改的就将更新的值存入到数据库，没有的填的就是null）
	public void updateBasicUsers(Userinfos us){
		String sql = "update userinfos set username=?,usersex=?,alwaddress=?,actaddress=?,introducemyself=? where userid=? ";
		DataHandler.update(sql, new Object[]{us.getUsername(),us.getUsersex(),us.getAlwaddress(),us.getActaddress(),us.getIntroducemyself(),us.getUserid()});
	}
	
	
	//更新个人头像
	public void updateUserpic(Userinfos us){
		String sql = "update userinfos set userpic=? where userid=?";
		DataHandler.update(sql, new Object[]{us.getUserpic(),us.getUserid()});
	}
	
	//更新收货地址
		public void updateAddres(Userinfos us){
			String sql = "update userinfos set name=?,goodsaddress=?,detailaddress=?,postcode=?,telephone=? where userid=? ";
			DataHandler.update(sql, new Object[]{us.getName(),us.getGoodsaddress(),us.getDetailaddress(),us.getPostcode(),us.getTelephone(),us.getUserid()});
		}
		
	//更新密码
	public void updatePassword(Userinfos us){
		String sql = "update userinfos set password=? where userid=?";
		DataHandler.update(sql, new Object[]{us.getPassword(),us.getUserid()});
	}
	
	//更新手机号
	public void updaTelephone(Userinfos us){
		String sql = "update userinfos set telephone=? where userid=?";
		DataHandler.update(sql, new Object[]{us.getTelephone(),us.getUserid()});
	}
	
	//删除用户信息
	public void deleteUsers(int userid){
		String sql = "delete from userinfos where userid=?";
		DataHandler.update(sql, new Object[]{userid});
	}
	
	//分页
	public <E>List<E> findCurrentPageData(PageHandler handler){
		return null;
	}
	
	public int findCountPage(PageHandler handler){
		return 0;
	}
}